<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="axios.js"></script>
</head>

<body>
    <button id="btn1">发起GET请求</button>
    <button id="btn2">发起POST请求</button>
    <button id="btn3">直接使用axios发起GET请求</button>
    <button id="btn4">直接使用axios发起POST请求</button>
    <script>
        document.querySelector('#btn1').addEventListener('click', function () {
            var url = 'http://www.liulongbin.top:3006/api/get'
            var obj = { name: 'zs', age: 20 }
            axios.get(url, { params: obj }).then(function (res) {
                console.log(res);
            })
        })

        document.querySelector('#btn2').addEventListener('click', function () {
            var url1 = 'http://www.liulongbin.top:3006/api/post'
            var obj1 = { location: '北京', address: '顺义' }
            axios.post(url1, obj1).then(function (res) {
                console.log(res);
            })
        })

        document.querySelector('#btn3').addEventListener('click', function () {
            axios({
                method: 'GET',
                url: 'http://www.liulongbin.top:3006/api/get',
                params: {
                    name: '厕所老八',
                    age: 23,

                },
            }).then(function (res) {
                console.log(res);
            })
        })

        document.querySelector('#btn4').addEventListener('click', function () {
            axios({
                method: 'POST',
                url: 'http://www.liulongbin.top:3006/api/post',
                data: {
                    name: '娃哈哈',
                    age: 18,
                    gender: '女'
                },
            }).then(function (res) {
                console.log(res.data);
            })
        })
        
    </script>
</body>

</html>